#include <windows.h>
#include <stdio.h>

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszCmdParam, int nCmdShow)
{

    HDC dc1, dc2, dc3, dc4;
    //WCHAR fname1[] = {'s','e','r','i','f', 0};
    WCHAR fname1[] = {'r','a','n','d','o', 'm', 0};
    WCHAR fname2[] = {'M','S',' ','S','a','n','s',' ','S','e','r','i','f', 0};
    WCHAR fname3[] = {'S','i','m','S','u','n', 0};
    WCHAR fname4[] = {'T','a','h','o','m','a', 0};
    LOGFONTW lf;
    HFONT font;
    WCHAR str1[] = {0x4e2d, 0x41, 0};
    WCHAR str2[] = {0x42, 0x41, 0};
    WCHAR str3[] = {0x41, 0x4e2d, 0};
    WORD gp1[2], gp2[2], gp3[2];
    DWORD ret;

    dc1= CreateCompatibleDC(NULL);
    lf.lfHeight = -16;
    lf.lfCharSet = 1;
    lstrcpyW(lf.lfFaceName, fname1);
    font = CreateFontIndirectW(&lf);
    SelectObject(dc1, font);
    gp1[0]=0;
    gp1[1]=0;
    ret = GetGlyphIndicesW(dc1, str1, 2, gp1, 0);
    printf("ret = %d\n", ret);
    printf("random str1(Chinese, ASCII): gp1[0]: %d, gp1[1]:%d\n", gp1[0], gp1[1]);
    gp2[0]=0;
    gp2[1]=0;
    ret = GetGlyphIndicesW(dc1, str2, 2, gp2, 0);
    printf("ret = %d\n", ret);
    printf("random str2(ASCII, ASCII): gp2[0]: %d, gp2[1]:%d\n", gp2[0], gp2[1]);
    gp3[0]=0;
    gp3[1]=0;
    ret = GetGlyphIndicesW(dc1, str3, 2, gp3, 0);
    printf("ret = %d\n", ret);
    printf("random str3(ASCII, Chinese): gp3[0]: %d, gp3[1]:%d\n", gp3[0], gp3[1]);
    printf("\n");
    DeleteObject(font);
    DeleteDC(dc1);

    dc2 = CreateCompatibleDC(NULL);
    lf.lfHeight = -16;
    lf.lfCharSet = 1;
    lstrcpyW(lf.lfFaceName, fname2);
    font = CreateFontIndirectW(&lf);
    SelectObject(dc2, font);
    gp1[0]=0;
    gp1[1]=0;
    ret = GetGlyphIndicesW(dc2, str1, 2, gp1, 0);
    printf("ret = %d\n", ret);
    printf("MS Sans Serif, str1(Chinese, ASCII): gp1[0]: %d, gp1[1]:%d\n", gp1[0], gp1[1]);
    gp2[0]=0;
    gp2[1]=0;
    ret = GetGlyphIndicesW(dc2, str2, 2, gp2, 0);
    printf("ret = %d\n", ret);
    printf("MS Sans Serif str2(ASCII, ASCII): gp2[0]: %d, gp2[1]:%d\n", gp2[0], gp2[1]);
    gp3[0]=0;
    gp3[1]=0;
    ret = GetGlyphIndicesW(dc2, str3, 2, gp3, 0);
    printf("ret = %d\n", ret);
    printf("MS Sans Serif str3(ASCII, Chinese): gp3[0]: %d, gp3[1]:%d\n", gp3[0], gp3[1]);
    printf("\n");

    DeleteObject(font);
    DeleteDC(dc2);

    dc3 = CreateCompatibleDC(NULL);
    lf.lfHeight = -16;
    lf.lfCharSet = 1;
    lstrcpyW(lf.lfFaceName, fname3);
    font = CreateFontIndirectW(&lf);
    SelectObject(dc3, font);

    gp1[0]=0;
    gp1[1]=0;
    ret = GetGlyphIndicesW(dc3, str1, 2, gp1, 0);
    printf("ret = %d\n", ret);
    printf("SimSun str1(Chinese, ASCII): gp1[0]: %d, gp1[1]:%d\n", gp1[0], gp1[1]);
    gp2[0]=0;
    gp2[1]=0;
    ret = GetGlyphIndicesW(dc3, str2, 2, gp2, 0);
    printf("ret = %d\n", ret);
    printf("SimSun str2(ASCII, ASCII): gp2[0]: %d, gp2[1]:%d\n", gp2[0], gp2[1]);
    gp3[0]=0;
    gp3[1]=0;
    ret = GetGlyphIndicesW(dc3, str3, 2, gp3, 0);
    printf("ret = %d\n", ret);
    printf("SimSun str3(ASCII, Chinese): gp3[0]: %d, gp3[1]:%d\n", gp3[0], gp3[1]);
    printf("\n");

    DeleteObject(font);
    DeleteDC(dc3);

    dc4 = CreateCompatibleDC(NULL);
    lf.lfHeight = -16;
    lf.lfCharSet = 1;
    lstrcpyW(lf.lfFaceName, fname4);
    font = CreateFontIndirectW(&lf);
    SelectObject(dc4, font);
    gp1[0]=0;
    gp1[1]=0;
    ret = GetGlyphIndicesW(dc4, str1, 2, gp1, 0);
    printf("ret = %d\n", ret);
    printf("Tahoma str1(Chinese, ASCII): gp1[0]: %d, gp1[1]:%d\n", gp1[0], gp1[1]);
    gp2[0]=0;
    gp2[1]=0;
    ret = GetGlyphIndicesW(dc4, str2, 2, gp2, 0);
    printf("ret = %d\n", ret);
    printf("Tahoma str2(ASCII, ASCII): gp2[0]: %d, gp2[1]:%d\n", gp2[0], gp2[1]);
    gp3[0]=0;
    gp3[1]=0;
    ret = GetGlyphIndicesW(dc4, str3, 2, gp3, 0);
    printf("ret = %d\n", ret);
    printf("Tahoma str3(ASCII, Chinese): gp3[0]: %d, gp3[1]:%d\n", gp3[0], gp3[1]);
    printf("\n");

    DeleteObject(font);
    DeleteDC(dc4);

    return 0;
}

